import Vue from 'vue'
import axios from 'axios'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'

// 导入loadsh
import _ from 'lodash'

// 导入NProgress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 导入全局样式
import './assets/css/global.css'

// 导入字体图标
import './assets/font/iconfont.css'

// 导入树状表格插件
import TreeTable from 'vue-table-with-tree-grid'

// 导入滑块验证码
import SlideVerify from 'vue-monoplasty-slide-verify'

// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// 导入富文本编辑器对应的样式
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
Vue.use(VueQuillEditor)
Vue.use(SlideVerify)

// 挂载lodash到vue原型上
Vue.prototype._ = _

// 将axios挂载到vue原型上
Vue.prototype.$http = axios
// 全局过滤时间过滤器
Vue.filter('dateFilter', (origin) => {
  const dt = new Date(origin)
  const year = dt.getFullYear()
  const mounth = (dt.getMonth() + 1 + '').padStart(2, '0')
  const day = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${year}-${mounth}-${day} ${hh}:${mm}:${ss}`
})
// 配置请求的根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
// 请求拦截，在请求前必须在请求头加上token认证
// 在请求拦截器中，展示进度条Nprofress.start()
axios.interceptors.request.use(config => {
  console.log('请求', config)
  NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 在最后必须return config
  return config
})

// 在响应拦截器中，隐藏NProfress.done()
axios.interceptors.response.use(config => {
  console.log('响应', config)
  NProgress.done()
  return config
})

Vue.config.productionTip = false
Vue.component('tree-table', TreeTable)
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
